www.gusucode.com > VC++ 汽配销售管理系统(Access)源码程序 > VC++ 汽配销售管理系统(Access)源码程序/源码/DMerchandise.cpp

    //Download by http://www.NewXing.com
// DMerchandise.cpp : implementation file
//

#include "stdafx.h"
#include "qpglxt.h"
#include "DMerchandise.h"
#include "DBaseQuery.h"
#include "RxGrid.h"
#include "externDllHeader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDMerchandise dialog


CDMerchandise::CDMerchandise(CWnd* pParent /*=NULL*/)
	: CDialog(CDMerchandise::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDMerchandise)
	//}}AFX_DATA_INIT
	AddOrChange=0;
}


void CDMerchandise::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDMerchandise)
	DDX_Control(pDX, IDC_SPXX_EDTSELL, m_Sell);
	DDX_Control(pDX, IDC_SPXX_COMUNIT, m_ComUnit);
	DDX_Control(pDX, IDC_SPXX_EDTSPEC, m_EdtSpec);
	DDX_Control(pDX, IDC_SPXX_EDTTYPE, m_EdtType);
	DDX_Control(pDX, IDC_SPXX_EDTPRICE, m_EdtPrice);
	DDX_Control(pDX, IDC_SPXX_EDTNAME, m_EdtName);
	DDX_Control(pDX, IDC_SPXX_EDTMEM, m_EdtMem);
	DDX_Control(pDX, IDC_SPXX_EDTID, m_EdtID);
	DDX_Control(pDX, IDC_SPXX_EDTCNAME, m_EdtCName);
	DDX_Control(pDX, IDC_SPXX_EDTAREA, m_EdtArea);
	DDX_Control(pDX, IDC_SPXX_BUTUNDO, m_ButUndo);
	DDX_Control(pDX, IDC_SPXX_BUTSAVE, m_ButSave);
	DDX_Control(pDX, IDC_SPXX_BUTEXIT, m_ButExit);
	DDX_Control(pDX, IDC_SPXX_BUTDELE, m_ButDelete);
	DDX_Control(pDX, IDC_SPXX_BUTCHANGE, m_ButChange);
	DDX_Control(pDX, IDC_SPXX_BUTADD, m_ButAdd);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDMerchandise, CDialog)
	//{{AFX_MSG_MAP(CDMerchandise)
	ON_BN_CLICKED(IDC_SPXX_BUTADD, OnSpxxButadd)
	ON_BN_CLICKED(IDC_SPXX_BUTCHANGE, OnSpxxButchange)
	ON_BN_CLICKED(IDC_SPXX_BUTDELE, OnSpxxButdele)
	ON_BN_CLICKED(IDC_SPXX_BUTSAVE, OnSpxxButsave)
	ON_BN_CLICKED(IDC_SPXX_BUTUNDO, OnSpxxButundo)
	ON_BN_CLICKED(IDC_SPXX_BUTEXIT, OnSpxxButexit)
	ON_EN_CHANGE(IDC_SPXX_EDTNAME, OnChangeSpxxEdtname)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDMerchandise message handlers

void CDMerchandise::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CDMerchandise::Display(CString ID)
{	
	RxRecordset Drxt;
	CString sSQL;
	if(ID.IsEmpty())
		return;

	sSQL.Format("SELECT * FROM 商品信息查询 WHERE 编号 ='%s'",ID);
	Drxt.Open(sSQL,adCmdText);

	CString sID,sName,sCName,sUnit,sType,sSell,sArea,sPrice,sMem,sSpec;
	sID=Drxt.GetFieldValue("编号");
	sName=Drxt.GetFieldValue("名称");
	sCName=Drxt.GetFieldValue("简称");
	sUnit=Drxt.GetFieldValue("计量单位");
	sType=Drxt.GetFieldValue("适用车型");
	sArea=Drxt.GetFieldValue("产地");
	sPrice=Drxt.GetFieldValue("进价");
	sMem=Drxt.GetFieldValue("备注");
	sSpec=Drxt.GetFieldValue("规格");
	sSell=Drxt.GetFieldValue("销售价格");
	this->m_EdtSpec.SetWindowText(sSpec);
	this->m_EdtArea.SetWindowText(sArea);
	this->m_EdtCName.SetWindowText(sCName);
	this->m_EdtID.SetWindowText(sID);
	this->m_EdtMem.SetWindowText(sMem);
	this->m_EdtName.SetWindowText(sName);
	this->m_EdtPrice.SetWindowText(sPrice);
	this->m_EdtType.SetWindowText(sType);
	this->m_ComUnit.SetWindowText(sUnit);
	this->m_Sell.SetWindowText(sSell);
}

BOOL CDMerchandise::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CDBaseQuery* Parent =(CDBaseQuery*)this->FindWindow(NULL,"商品信息查询");
	CString sSQL,sID;
	sID=Parent->m_Grid.GetItemText(Parent->m_CurrentRow,0);
	m_sID=sID;
	this->Display(sID);
	rst.Open("计量单位表");
	this->m_ComUnit.SetRecordset(rst,"计量单位");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDMerchandise::Enabled(bool bEnabled)
{
	m_EdtArea.EnableWindow(bEnabled);
	m_EdtCName.EnableWindow(bEnabled);
	this->m_Sell.EnableWindow(bEnabled);
	m_EdtMem.EnableWindow(bEnabled);
	m_EdtSpec.EnableWindow(bEnabled);
	m_EdtName.EnableWindow(bEnabled);
	m_EdtPrice.EnableWindow(bEnabled);
	m_EdtType.EnableWindow(bEnabled);
	m_ComUnit.EnableWindow(bEnabled);
	m_ButUndo.EnableWindow(bEnabled);
	m_ButSave.EnableWindow(bEnabled);
	m_ButExit.EnableWindow(!bEnabled);
	m_ButDelete.EnableWindow(!bEnabled);
	m_ButChange.EnableWindow(!bEnabled);
	m_ButAdd.EnableWindow(!bEnabled);
	if(bEnabled==true)
		this->m_EdtName.SetFocus();
	else
		this->m_ButSave.SetFocus();


}

void CDMerchandise::Clear()
{
	m_EdtArea.SetWindowText("");
	m_EdtCName.SetWindowText("");
	m_EdtMem.SetWindowText("");
	m_EdtName.SetWindowText("");
	m_EdtPrice.SetWindowText("");
	m_EdtType.SetWindowText("");
	m_ComUnit.SetWindowText("");
	m_EdtSpec.SetWindowText("");
	m_Sell.SetWindowText("");
}

void CDMerchandise::OnSpxxButadd() 
{
	AddOrChange=1;
	CString sNewID;
	sNewID=ado.AutoNumber("商品信息表","编号","SP",2);
	this->Clear();
	m_EdtID.SetWindowText(sNewID);
	this->Enabled(true);
	this->m_EdtName.SetFocus();

}

void CDMerchandise::OnSpxxButchange() 
{
	AddOrChange=2;
	this->Enabled(true);
	this->m_EdtName.SetFocus();	
}

void CDMerchandise::OnSpxxButdele() 
{
	if(MessageBox("确定要删除记录吗?"," 系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
		return;
	CString cID,sSQL;
	this->m_EdtID.GetWindowText(cID);
	sSQL.Format("DELETE FROM 商品信息表 WHERE 编号='%s'",cID);
	if(rst.Open(sSQL,adCmdText)==false)
	{
		MessageBox("对不起!由于仓库中存在此中商品,所以您不能删除此条记录!","系统提示",MB_OK|MB_ICONSTOP);
		return;
	}
	this->OnCancel();
	
}

void CDMerchandise::OnSpxxButsave() 
{
	if(MessageBox("确定要保存记录吗?"," 系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
		return;
	CString sSQL,sID,sName,sSell,sCName,sUnitID,sUnit,sType,sArea,sPrice,sMem,sSpec;
	m_EdtID.GetWindowText(sID);
	m_EdtArea.GetWindowText(sArea);
	m_EdtCName.GetWindowText(sCName);
	m_EdtMem.GetWindowText(sMem);
	m_EdtName.GetWindowText(sName);
	m_EdtPrice.GetWindowText(sPrice);
	m_EdtType.GetWindowText(sType);
	m_ComUnit.GetWindowText(sUnit);
	m_EdtSpec.GetWindowText(sSpec);
	m_Sell.GetWindowText(sSell);
	sUnitID=ado.FieldToOtherField("计量单位表","计量单位",sUnit,"编号",1);
	if(this->AddOrChange==1)//添加
		sSQL.Format("INSERT INTO 商品信息表 VALUES('%s','%s','%s','%s','%s','%s',%s,%s,%s,'%s')",sID,sName,sCName,sType,sSpec,sArea,sUnitID,sPrice,sSell,sMem);
	else//修改
		sSQL.Format("UPDATE 商品信息表 SET 名称='%s',简称='%s',适用车型='%s',规格='%s',产地='%s',单位=%s,进价=%s,销售价格=%s,备注='%s' WHERE 编号='%s'",sName,sCName,sType,sSpec,sArea,sUnitID,sPrice,sSell,sMem,sID);

	rst.Open(sSQL,adCmdText);
	this->Enabled(false);
	this->AddOrChange=0;
}

void CDMerchandise::OnSpxxButundo() 
{
	if(MessageBox("确定要撤消操作吗?"," 系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
		return;
	this->Enabled(false);
	this->Clear();
	this->Display(m_sID);
}

void CDMerchandise::OnSpxxButexit() 
{
	this->OnCancel();	
}

void CDMerchandise::OnChangeSpxxEdtname() 
{
	CString sName,sSName;
	this->m_EdtName.GetWindowText(sName);
	sSName=CharToLetterCode(sName);
	this->m_EdtCName.SetWindowText(sSName);
}